#include <nice2d/messagereceiver.h>

void MessageReceiver::registerMessageListener(MessageListenerPointer listener)
{
    if(listener)
        listeners.push_back(listener);
}

void MessageReceiver::unregisterMessageListener(MessageListenerPointer listener)
{
    if(listener)
        listeners.remove(listener);
}

bool MessageReceiver::process(std::shared_ptr<Message> message)
{
    auto itr = listeners.begin();
    while(itr != listeners.end())
    {
        if((*itr)->onListener(message))
            return true;
        itr ++;
    }
    return false;
}
